<?php
namespace Admin\Controller;

class SmtpController extends BaseController{
	public function index(){
		$Smtp = D('Smtp');
		$object = $Smtp->all($this->page($Smtp->total()));
		$this->assign('All',$object);
		$this->display();
	}
	
	public function add(){
		if (IS_POST){
			//$this->failed('演示站，数据无法添加！');
			$Smtp = D('Smtp');
			$object = $Smtp->insert();
			if (is_numeric($object)){
				$object>0 ? $this->success(U(CONTROLLER_NAME.'/index'),'SMTP服务器添加成功！') : $this->failed('SMTP服务器添加失败！');
			}else{
				$this->failed($object);
			}
		}
		$this->display();
	}
	
	public function state(){
		$Smtp = D('Smtp');
		$object = array();
		if ($Smtp->total() > 0){
			foreach (range(0,23) as $value){
				$temp = $Smtp->one3($value);
				if ($value < 10) $value = '0'.$value;
				$temp['hour'] = $value;
				$object[] = $temp;
			}
		}
		$this->assign('All',$object);
		$this->display();
	}
	
	public function update(){
		if (I('get.id')){
			$Smtp = D('Smtp');
			if (IS_POST){
				//$this->failed('演示站，数据无法修改！');
				$object = $Smtp->update();
				is_numeric($object) ? $this->success(U(CONTROLLER_NAME.'/index'),'SMTP服务器修改成功！') : $this->failed($object);
			}
			$object = $Smtp->one();
			if (!$object) $this->failed('不存在此SMTP服务器！');
			$this->assign('One',$object);
			$this->display();
		}else{
			$this->failed('非法操作！');
		}
	}
	
	public function delete(){
		if (I('get.id')){
			$Smtp = D('Smtp');
			if (IS_POST){
				//$this->failed('演示站，数据无法删除！');
				$Smtp->remove() ? $this->success(I('post.prev'),'SMTP服务器删除成功！') : $this->failed('SMTP服务器删除失败！');
			}
			if (!$Smtp->one()) $this->failed('不存在此SMTP服务器！');
			$this->confirm('您真的要删除这条数据么？');
		}else{
			$this->failed('非法操作！');
		}
	}
}